package com.work.crops.dao;

import com.work.crops.pojo.CropsDisease;
import com.work.crops.pojo.CropsParam;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface CropsDiseaseMapper extends Mapper<CropsDisease> {

    @Select("<script>" +
            "SELECT * FROM t_crops_disease " +
            "<if test=\"empty != 'alin' \"> WHERE id in (" +
            "SELECT did from t_crops_info_disease " +
            "   WHERE cid in (SELECT id FROM t_crops_info " +
            "    <if test=\"name != null and name != ''\">WHERE `name`  = #{name} </if>) " +   //根据农作物名称查询条件
            "     <if test=\"stage != null and stage != ''\"> AND stage = #{stage} </if>) " +         // 根据生长阶段
            "<if test=\"stage != null and stage != ''\"> AND aspect LIKE '%'#{aspect}'%' </if> " +          // 表现特征
            "<if test=\"stage != null and stage != ''\">AND `name` LIKE '%'#{dname}'%' </if>" +           //病虫害名称
            "</if> </script>")
    List<CropsDisease> findByPage(CropsParam cropsDiseaseParam);


    @Select("SELECT * FROM t_crops_disease WHERE id = (SELECT did FROM t_crops_info_disease WHERE cid = #{id})")
    List<CropsDisease> findByCropsId(Long id);
}
